import os
import msvcrt
import pandas as pd

def file_name(file_dir):
    for root, dirs, files in os.walk(file_dir):
        return files

def zhuanhuan(filename):
    file = filename.split("\n")
    text = ''
    for para in file:
        if str(para).strip() == "":
            continue
        else:
            text += (str(para).strip())
            text += ("<seg>\n")
    return text

def savefile(filename):
    data = pd.read_excel(filename)
    res = pd.DataFrame(columns=data.columns)

    for i in range(len(data)):
        text = zhuanhuan(data.iloc[:, 2][i])
        res = res.append([{data.columns[0]: data.iloc[i][0],
                           data.columns[1]: data.iloc[i][1],
                           data.columns[2]: text,
                           data.columns[3]: data.iloc[i][3],
                           data.columns[4]: data.iloc[i][4],
                           data.columns[5]: data.iloc[i][5],
                           data.columns[6]: data.iloc[i][6],
                           data.columns[7]: data.iloc[i][7],
                           data.columns[8]: data.iloc[i][8],
                           data.columns[9]: data.iloc[i][9],
                           data.columns[10]: data.iloc[i][10],
                           data.columns[11]: data.iloc[i][11],
                           data.columns[12]: data.iloc[i][12],
                           data.columns[13]: data.iloc[i][13], }], ignore_index=True)
    res = res.fillna("null")
    res.to_excel(str(filename).strip(".xlsx")+"output.xlsx", index=0)

file_dir = os.getcwd()
try:
    for i in file_name(file_dir):
        if str(i).split(".")[-1] != "xlsx":
            continue
        else:
            savefile(i)
except Exception as e:
    print(e)
print("请按任意键退出~")
ord(msvcrt.getch())







